package com.zhangwei.xmppdemo;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import cn.finalteam.okhttpfinal.HttpRequest;
import cn.finalteam.okhttpfinal.StringHttpRequestCallback;

/**
 * @version V1.0
 * @description:
 * @title: Expands
 * @package com.zhangwei.xmppdemo
 * @author: zhangwei
 * @date: 2015-12-22 下午4:25
 * 显示加载数据失败
 */
@EActivity(R.layout.activity_viewsub)
public class ViewStubActivity extends AppCompatActivity {
    View failView;
    @ViewById
    Button returnBtn;
    @ViewById
    TextView title;
    @ViewById
    Button leftBtn;
    @ViewById
    ListView comLv;
    @ViewById
    ImageView emptyImg;


    @AfterViews
    public void initData() {
        comLv.setEmptyView(emptyImg);


        HttpRequest.get("https://github.com/pengjianbo/OkHttpFinal/wiki", new StringHttpRequestCallback() {
            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            protected void onSuccess(String s) {
                super.onSuccess(s);
            }

            @Override
            public void onProgress(int progress, long networkSpeed, boolean done) {
                super.onProgress(progress, networkSpeed, done);


            }

            @Override
            public void onFailure(int errorCode, String msg) {
                super.onFailure(errorCode, msg);

                if (failView == null) {
                    ViewStub viewStub = (ViewStub) findViewById(R.id.viewStub);
                    failView = viewStub.inflate();
                }
                failView.setVisibility(View.VISIBLE);
                showFailView(failView);
            }
        });
    }

    private void showFailView(View failView) {
        Button refreshBtn = (Button) failView.findViewById(R.id.refresh_btn);
        refreshBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
            }
        });
    }


}
